package com.homedroid.dal;

import java.util.ArrayList;

public class Product {
	private String amount = "error";
	private String actual_amount = "error";
	private String barcode = "error";
	private String label = "error";
	private String brand = "error";
	private String content_ = "error";
	private String content_2 = "error";
	private String unit = "error";
	private StringBuffer buffer = new StringBuffer();
	private StringBuffer desc;
	private ArrayList<Product> onStockList = new ArrayList<Product>();


	public ArrayList<Product> getOnStockList(){
		return onStockList;
	}
	
	public Product() {
		desc = new StringBuffer();
	}

	public Product(Product old, String amount) {
		this.amount = amount;
		barcode = old.getBarcode();
		label = old.getLabel();
		brand = old.getBrand();
		content_ = old.getContent_();
		content_2 = old.getContent_2();
		unit = old.getUnit();
	}
	public Product(String amount, String actual_amount, String barcode, String label, String brand, String content_, String content_2, String unit) {
		this.amount = amount;
		this.actual_amount = actual_amount;
		this.barcode = barcode;
		this.label = label;
		this.brand = brand;
		this.content_ = content_;
		this.content_2 = content_2;
		this.unit = unit;
	}
	
	public void resetDescBuffer(){
		desc = null;
	}

	public StringBuffer getBuffer(){
		return buffer;
	}
	public void resetBuffer(){
		buffer = null;
	}
	public void setAmount(String amount) {
		this.amount = amount;
		buffer.append(":" + amount + ",");
	}
	
	public String getAmount() {
		return amount;
	}
	public void setBarcode(String barcode) {
		this.barcode = barcode;
		buffer.append(barcode + ",");
	}
	
	public String getBarcode() {
		return barcode;
	}
	
	public void setLabel(String label) {
		this.label = label;
		buffer.append(label + ",");
	}

	public String getLabel() {
		return label;
	}

	public void setBrand(String brand) {
		this.brand = brand;
		buffer.append(brand + ",");
	}

	public String getBrand() {
		return brand;
	}

	public void setContent_(String content_) {
		this.content_ = content_;
		buffer.append(content_ + ",");
	}

	public String getContent_() {
		return content_;
	}

	public void setContent_2(String content_2) {
		this.content_2 = content_2;
		buffer.append(content_2 + ",");
	}

	public String getContent_2() {
		return content_2;
	}

	public void setUnit(String unit) {
		this.unit = unit;
		buffer.append(unit);
	}

	public String getUnit() {
		return unit;
	}



	public int getUid(String unit) {
		if (unit.equalsIgnoreCase("pc")) {
			return 1;
		} else if (unit.equalsIgnoreCase("pcs")) {
			return 2;
		} else if (unit.equalsIgnoreCase("g")) {
			return 3;
		} else if (unit.equalsIgnoreCase("kg")) {
			return 4;
		} else if (unit.equalsIgnoreCase("ml")) {
			return 5;
		} else if (unit.equalsIgnoreCase("l")) {
			return 6;
		}
		return 0;

	}

	public String getDescription() {
		return amount + "x - " + label + " " + content_ + "," + content_2 + unit;
	}

	public String getUnitString(int u_id) {
		if (u_id == 1) {
			return "pc";
		} else if (u_id == 2) {
			return "pcs";
		} else if (u_id == 3) {
			return "g";
		} else if (u_id == 4) {
			return "kg";
		} else if (u_id == 5) {
			return "ml";
		} else if (u_id == 6) {
			return "l";
		}
		return null;
	}

	public String getDescription(StringBuffer buffer2) {
		String[] products = buffer2.toString().split(":");
		desc = new StringBuffer();
		for(int i = 1; i < products.length; i++){
			String[] items = products[i].toString().split(",");
			desc.append(":" + items[0] + "x - " + items[2] + "    " + items[4] + "," + items[5] + items[6] + "\n        " + items[3]);

		}
		System.out.println(desc);
		return desc.toString();
	}

	public void setActualAmount(String actual_amount) {
		this.actual_amount = actual_amount;

	}

	public String getActualAmount() {
		return actual_amount;
	}
	
	public void addToOnStockList(){
		onStockList.add(new Product(amount, actual_amount, barcode, label, brand, content_, content_2, unit));
		
	}
	

}
